{% extends '_base_create_update.html' %}

{% block top_css %}
    {{ super() }}

    <!--Treeview-->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='plugins/bootstrap-treeview/css/bootstrap-treeview.min.css') }}">
    <!--bees-->
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bees.css') }}">

{% endblock %}


<!-- Content head -->
{% block head_title %}
    系统管理
{% endblock %}

{% block head_nav %}
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-home"></i></a></li>
        <li><a href="#">权限管理</a></li>
        <li class="active">权限菜单</li>
    </ol>
{% endblock %}

<!-- Content body -->
{% block body_title %}
    修改权限菜单
{% endblock %}

{% block body_form %}
    <form name="privilegesForm" action="" class="form-horizontal">
        <div class="panel-body">
            <p class="bord-btm pad-ver text-main text-bold">权限信息</p>

            <div class="row">
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label"><span class="text-danger">* </span>规则名称</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="name" value="{{ name }}" placeholder="请输入规则名称" data-rule="规则名称: required;" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">上级菜单</label>
                            <div class="col-lg-8">
                                <div class="menu-wrap">
                                    <div class="menu-wrap">
                                    <div class="menu-select">
                                        <select class="form-control" name="pid">
                                        </select>
                                        <span class="form-control collapse">请选择上级菜单</span>
                                    </div>
                                    <div class="menu-tree"></div>
                                </div>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">所属模块</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="module" value="{{ module }}" placeholder="请输入所属模块" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">所属视图</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="controller" value="{{ controller }}" placeholder="请输入所属模块" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">请求类型</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="action" value="{{ action }}" placeholder="请输入请求类型" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">显示菜单</label>
                            <div class="col-lg-8">
                                <div class="checkbox">
                                    <input id="radio-menu-show" class="magic-radio" type="radio" name="is_menu" value="1" {% if is_menu %} checked {% endif %}>
                                    <label for="radio-menu-show">是</label>

                                    <input id="radio-menu-none" class="magic-radio" type="radio" name="is_menu" value="0" {% if not is_menu %} checked {% endif %}>
                                    <label for="radio-menu-none">否</label>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">显示顺序</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="sort" value="{{ sort }}" placeholder="请输入一个数值" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
                <div class="col-lg-12">
                    <fieldset class="pad-top">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">图标样式</label>
                            <div class="col-lg-8">
                                <input type="text" class="form-control" name="icon" value="{{ icon }}" placeholder="请输入Font Awesome类样式" autocomplete="off">
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>
        </div>

        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-6 col-sm-offset-6">
                    <div class="col-sm-7 col-sm-offset-3">
                        <button class="btn btn-mint pull-right" type="submit">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
{% endblock %}



{% block buttom_js %}
    {{ super() }}
    <!--bees-->
    <script src="{{ url_for('static', filename='js/bees.js') }}"></script>
    <!--Treeview-->
    <script src="{{ url_for('static', filename='plugins/bootstrap-treeview/js/bootstrap-treeview.min.js') }}"></script>

    <script type="text/javascript">

        $(function () {

            (function () {
                $.ajax({
                    type: 'get',
                    url: '{{ url_for("perms.api-permission-menu") }}',
                    success: function (menus) {
                        bees.initMenuTree($(".menu-tree"), {
                            data: menus  // 默认选中
                        }, '{{ pid }}'.split(','));
                    }
                });
            })();

            bees.initSelect2({
                // allowClear: true
            });

            var $formEle = $('form[name="privilegesForm"]');
            bees.niceValidate($formEle);
            $formEle.on("valid.form", function () {
                setAjaxCSRFToken();
                $.ajax({
                    type: 'post',
                    url: '{{ url_for("perms.permission-update", pk=default_pk) }}'.replace(bees.defaultPK, '{{ id }}'),
                    data : $formEle.serialize(),
                    success: function (result) {
                        if (result.code != 200) {
                            $formEle.find('*[name='+ result.data.field +']').focus().addClass('has-error');
                            bees.tipError({
                                message: result.data.message
                            });
                        }else {
                            bees.tipInfo({
                                message: '修改成功'
                            });
                            window.location.href = '{{ url_for("perms.permission-list") }}'
                        }
                    }
                });
            })
        })

    </script>

{% endblock %}
